﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Viettel.VOFFICE.DAO.Models;

namespace Viettel.VOFFICE.Web.Models
{
    /// <summary>
    /// model phòng ban
    /// </summary>
    public class DepartmentModel : BaseModel
    {
        public int Id { get; set; }

        [Required(ErrorMessageResourceType = typeof(Resources.Resources), ErrorMessageResourceName = "region")]
        public string Name { get; set; }

        public string Description { get; set; }
        public int Node { get; set; }
        public int? ParentId { get; set; }
        public bool? IsActive { get; set; }
        public string OfficeCode { get; set; }
        public DateTime CreatedAt { get; set; }
        public DateTime UpdatedAt { get; set; }
        public Guid? CreatorId { get; set; }
        public string ParentName { get; set; }
        public DepartmentModel DepartmentModel1 { get; set; }

        public DepartmentModel()
        {
            this.SubDepts = new List<DepartmentModel>();
        }
        //Parent-child
        public IList<DepartmentModel> SubDepts { get; private set; }
        public DepartmentModel(v_Department department)
        {
            Id = department.Id;
            Name = department.Name;
            Node = department.Node;
            Description = department.Description;
            ParentId = department.ParentId;
            IsActive = department.IsActive;
            OfficeCode = department.OfficeCode;
            CreatedAt = department.CreatedAt;
            UpdatedAt = department.UpdatedAt;
            CreatorId = department.CreatorId;
            if (ParentId != null)
            {
                ParentName = department.v_Department2.Name;
            }
        }
    }
    public class DeptTreeModel : BaseModel
    {
        public string data;
        public int id;
        public DeptTreeAttr attr;
        public List<DeptTreeModel> children;

        public DeptTreeModel() { }
        public DeptTreeModel(v_Department department)
        {
            data = department.Name;
            attr.id = department.Id;
            attr.title = department.Name;
        }
    }
    public class DeptTreeAttr
    {
        public int id;
        public string title;
    }
}